package com.dmc.controller;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dmc.service.PayrollService;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.zero.basic.exception.SmsErrorConstant;
import com.zero.basic.exception.SmsRuntimeException;
import com.zero.basic.exception.SmsStatusCode;
import com.zero.basic.model.Pager;
import com.zero.basic.util.JsonCreator;

@Controller("payrollSheetController")
@RequestMapping("payrollSheet")
public class PayrollSheetController {

	@Inject
	private PayrollService payrollService;
	
	@RequestMapping("/payroll_Query")
	@ResponseBody
	public Object searchItems(String depId, String empId, String fromDate, String toDate) {
		ObjectNode objectNode = JsonCreator.generateJsonObj();
		try {
//			Pager<PayrollDto> payrollPager = payrollService.getPayroll(depId, empId, fromDate, toDate);
			List<String> payrollItems = payrollService.getPayrollItems();
//			List<Map<String, String>> payrollRowInfo = payrollService.getPayrollRowInfo();
			List<Map<String, String>> payrollRows = payrollService.getPayrollRowData(depId, empId, fromDate, toDate);
			Pager<Map<String, String>> payrollData = new Pager<Map<String, String>>();
			payrollData.setDatas(payrollRows);
			objectNode.putPOJO("col_name", payrollItems);
			objectNode.putPOJO("col_data", payrollData);
//			objectNode.putPOJO("col_model", payrollRowInfo);
//			objectNode.putPOJO("rows", payrollRows);
//			objectNode.putPOJO("response", payrollPager);
			objectNode.put("message", "获取工资查询报表成功");
			objectNode.put("statusCode", SmsStatusCode.SUC_CODE);
			System.out.println(objectNode);
		} catch (SmsRuntimeException e) {
			objectNode.put("message", e.getErrorDescription());
			objectNode.put("error", e.getError());
			objectNode.put("statusCode", e.getStatusCode());
		} catch (Exception e) {
			e.printStackTrace();
			objectNode.put("message", SmsErrorConstant.SERVER_ERROR_MSG);
			objectNode.put("error", SmsErrorConstant.WEB_APPLICATION);
			objectNode.put("statusCode", SmsStatusCode.SERVER_ERROR);
		}
		return objectNode;
	}
}
